/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *  
 *
 * @author: jin Chen
 * @date: Jan 29, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.plot.ruler.tick;

import javax.swing.*;
import java.awt.*;

public class AxisLineTick extends LineTick{
    int axisLineLength;
    Color axisLineColor;
    Stroke axisLineStroke;
    boolean drawAxisLine=true;//

    //In OO theory, we should have make a Label obj. In practice, label bounds only determined by Graphics2D at paint time,to avoid overhead to update Label's bound(many things can affect it), we only keep the bounds as a temp solution
    // assume a label is associated with the tick to display tick value.
    Rectangle labelBounds=new Rectangle();

    public void paintComponent(Graphics g) {
        super.paintComponent(g);//draw tick

        //draw axisline
        Point p=this.getLocation();
        Point ep = getAxisLineEnd(p);
        Graphics2D g2d=(Graphics2D) g;

        if (isDrawAxisLine() ) {
            Stroke oldstk = g2d.getStroke();
            g2d.setStroke(this.getAxisLineStroke());
            g2d.drawLine(p.x, p.y,ep.x,ep.y);
            g2d.setStroke(oldstk);
        }
    }
    //return end point of tick
    protected  Point getAxisLineEnd(Point p) {
        Point ep=new Point();
        int ex=0,ey=0;//end point of tick

        int length = this.getAxisLineLength();
        int orient = this.getOrient();
        switch (orient ){
            case SwingConstants.TOP:
                ex=p.x;
                ey=p.y+ length;
                break;
             case SwingConstants.BOTTOM:
                ex=p.x;
                ey=p.y- length;
                break;
             case SwingConstants.LEFT:
                ex=p.x+ length;
                ey=p.y;
                break;
             case SwingConstants.RIGHT :
                ex=p.x- length;
                ey=p.y;
                break;
              default: assert false;//not expect happen;

        }
        ep.setLocation(ex,ey);
        return ep;
    }
    public int getAxisLineLength() {
        return axisLineLength;
    }

    public void setAxisLineLength(int axisLineLength) {
        this.axisLineLength = axisLineLength;
    }

    public Color getAxisLineColor() {
        return axisLineColor;
    }

    public void setAxisLineColor(Color axisLineColor) {
        this.axisLineColor = axisLineColor;
    }

    public Stroke getAxisLineStroke() {
        return axisLineStroke;
    }

    public void setAxisLineStroke(Stroke axisLineStroke) {
        this.axisLineStroke = axisLineStroke;
    }

    public boolean isDrawAxisLine() {
        return drawAxisLine;
    }

    public void setDrawAxisLine(boolean drawAxisLine) {
        this.drawAxisLine = drawAxisLine;
    }

    public Rectangle getLabelBounds() {
        return labelBounds;
    }

   public void setLabelBounds(int x, int y,int w, int h) {
        this.labelBounds.setBounds(x,y,w,h);
    }
    public void setLabelBounds(Rectangle r) {
        this.labelBounds=r;
    }

}
